<template>
  <el-container class="electronicSignature">
    <el-main class="mainDetails">
      <TCollapse title="决算送审信息">
        <div class="searchPanel-content">
          <FinalAccountsTable :colOptionEnum="dicLists" :tableData="tableData" :columns="checkColumnsDetails"
            :isSortNum="true">
            <template #prjName="{ scope }">
              <span @click="skipFinalAccounts(scope)" style="color:rgb(51, 170, 255);cursor: pointer;">
                {{ scope.prjName }}
              </span>
            </template>
          </FinalAccountsTable>
          <pagination v-if="pageParam.total > 10" :total="pageParam.total" :page.sync="pageParam.pageNum"
            :limit.sync="pageParam.pageSize" @pagination="doSearch" />
        </div>
      </TCollapse>
    </el-main>
  </el-container>
</template>

<script>
import FinalAccountsTable from '@/views/finalAccounts/components/finalAccountsTable.vue'
import SysConst from '@/common/const'
import { queryFinAuditList ,getDropdownDataApi} from '@/api/finalAccounts/index'
import { checkColumnsDetails } from '@/views/finalAccounts/setting'
export default {
  name: 'CheckFinalAccounts',
  components: {
    FinalAccountsTable
  },
  data() {
    return {
      pageParam: {
        pageSize: SysConst.PAGESIZE, // 每页显示val条
        pageNum: SysConst.CURRENT_PAGE, // 当前页
        total: SysConst.TOTAL// 总数
      },
      tableData: [],
      checkColumnsDetails,
      dicLists: {}
    }
  },
  methods: {
    skipFinalAccounts(row) {
      window.open(`${process.env.VUE_APP_ZHONGRUAN_URL}handleFinalAccounts?prjId=${row.prjId}&type=1`, '_blank')
    },
    async getInitInfo(item) {
      try {
        const params = {
          pageNum: item?.pageNum ? item?.pageNum : 1,
          pageSize: item?.pageSize ? item?.pageSize : 11,
          param: {
            prjCode: this.$route.query.prjCode,
            isPush:'02,03,04,05,06'
          }
        }
        const { data } = await queryFinAuditList(params)
        this.tableData = data
      } catch (error) {
        console.log(error)
      }
    },
    async doSearch(item) {
      const params = {
        pageNum: item?.page || SysConst.CURRENT_PAGE,
        pageSize: item?.limit || SysConst.PAGESIZE,
      }
      await this.getInitInfo(params)
    },
    async getDictData() {
      const arr = ['FIN_AUDIT_STATE', 'IS_PUSH']
      const promises = arr.map(item => getDropdownDataApi(item))
      const results = await Promise.all(promises)
      arr.forEach((item, i) => {
        this.$set(this.dicLists, item, results[i].data ?? [])
      })
    },
  },
  created() {
    this.getInitInfo()
    this.getDictData()
  }
}

</script>
<style lang="scss" scoped>
.electronicSignature {
  padding: 20px 45px;
  width: 100%;
}
</style>
